package com.suxii.handler;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChannelsHandler {

    // 全局单例管理
    public static ChannelGroup channelGroup =
            new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    // 将channel与uid绑定
    public static Map<Integer, Channel> channelMap=new HashMap<>();
    public static Map<Channel, Integer> uidlMap=new HashMap<>();


    // 绑定方法
    public static void bindChannel(int u,Channel ch){
        channelGroup.add(ch);
        channelMap.put(u,ch);
        uidlMap.put(ch,u);
    }

    // 移除
    public static void removeChannel(int u){
        Channel channel = channelMap.remove(u);
        uidlMap.remove(channel);
        channelGroup.remove(channel);
    }


    public static Map<Integer, List<String>> messageCache=new HashMap<>();

    // TODO 未在线的用户，消息缓存
    public static Map<Integer,Integer> noConnectUserCache=new HashMap<>();

}

